package x.ovo.wechat.bot.http.request.core;

import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.util.ReUtil;
import x.ovo.wechat.bot.common.Constant;
import x.ovo.wechat.bot.common.http.request.ApiRequest;
import x.ovo.wechat.bot.common.http.session.LoginSession;

import java.util.function.Function;

public class UuidRequest extends ApiRequest<String> {

    public UuidRequest(LoginSession session) {
        super(session);
    }

    @Override
    public String getUrl() {
        String redirectUrl = UrlBuilder.of(Constant.NEWLOGINPAGE).addQuery("mod", "desktop").build();

        return UrlBuilder.of(Constant.LOGINJS)
                .addQuery("appid", Constant.APP_ID)
                .addQuery("fun", "new")
                .addQuery("lang", "zh_CN")
                .addQuery("redirect_uri", redirectUrl)
                .addQuery("_", System.currentTimeMillis())
                .build();
    }

    @Override
    public Function<String, String> responseHandler() {
        return s -> ReUtil.get(Constant.UUID_PATTERN, s, 2);
    }
}
